package com.example.web.websystem.controller;

import com.example.web.websystem.controller.vo.form.SysRoleFormVO;
import com.example.web.websystem.dao.model.SysRoleDO;
import com.example.web.websystem.response.CommonReturnData;
import com.example.web.websystem.service.SysRoleService;
import com.example.web.websystem.util.DozerUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by YangGang on 2021/1/26 9:35。
 */
@RestController()
@RequestMapping("/sys/role")
public class SysRoleController {
    @Autowired
    private SysRoleService sysRoleService;


    @PostMapping("/addRole")
    public CommonReturnData addRole(SysRoleFormVO sysRoleFormVO) {
        SysRoleDO sysRole = DozerUtil.map(sysRoleFormVO, SysRoleDO.class);
        sysRoleService.addSysRole(sysRole);
        return CommonReturnData.success(sysRole.getRoleId());
    }

    @PostMapping("/updateRole")
    public CommonReturnData updateRole(SysRoleFormVO sysRoleFormVO) {
        SysRoleDO sysRole = DozerUtil.map(sysRoleFormVO, SysRoleDO.class);
        int up = sysRoleService.updateSysRole(sysRole);
        return CommonReturnData.success(up);
    }


}
